<?php

namespace App\Entity\Sale;

use ApiPlatform\Core\Annotation\ApiResource;
use App\Base\Annotation\Common;
use App\Repository\Sale\SaleMiaoRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * @ApiResource()
 * @ORM\Entity(repositoryClass=SaleMiaoRepository::class)
 */
class SaleMiao
{
    /**
     * @Common(cnName="#",listType="text",editType="text")
     * @Groups({"sale"})
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @Common(cnName="标题",listType="text",editType="text",width="")
     * @Groups({"sale"})
     * @ORM\Column(type="string", length=255)
     */
    private $title;

    /**
     * @Common(cnName="启动时间",listType="text",editType="datetime",width="200")
     * @Groups({"sale"})
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $startAt;

    /**
     * @Common(cnName="截止时间",listType="text",editType="datetime",width="200")
     * @Groups({"sale"})
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $endAt;

    /**
     * @Common(cnName="开始时间",listType="text",editType="time",width="200")
     * @Groups({"sale"})
     * @ORM\Column(type="string", length=255)
     */
    private $startTime;

    /**
     * @Common(cnName="结束时间",listType="text",editType="time",width="200")
     * @Groups({"sale"})
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $endTime;

    /**
     * @Common(cnName="周期X值",listType="text",editType="text",width="100")
     * @Groups({"sale"})
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $circle;

    /**
     * @Common(cnName="循环类型",listType="text",editType="select",width="200")
     * @Groups({"sale"})
     * @ORM\ManyToOne(targetEntity=SaleMiaoCircleType::class)
     * @ORM\JoinColumn(nullable=false)
     */
    private $circleType;

    /**
     * @ORM\OneToMany(targetEntity=SaleMiaoProduct::class, mappedBy="miao", orphanRemoval=true)
     */
    private $list;

    public function __construct()
    {
        $this->list = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getTitle(): ?string
    {
        return $this->title;
    }

    public function setTitle(string $title): self
    {
        $this->title = $title;

        return $this;
    }

    public function getStartAt(): ?\DateTimeInterface
    {
        return $this->startAt;
    }

    public function setStartAt(?\DateTimeInterface $startAt): self
    {
        $this->startAt = $startAt;

        return $this;
    }

    public function getEndAt(): ?\DateTimeInterface
    {
        return $this->endAt;
    }

    public function setEndAt(?\DateTimeInterface $endAt): self
    {
        $this->endAt = $endAt;

        return $this;
    }

    public function getStartTime(): ?string
    {
        return $this->startTime;
    }

    public function setStartTime(string $startTime): self
    {
        $this->startTime = $startTime;

        return $this;
    }

    public function getEndTime(): ?string
    {
        return $this->endTime;
    }

    public function setEndTime(?string $endTime): self
    {
        $this->endTime = $endTime;

        return $this;
    }

    public function getCircle(): ?string
    {
        return $this->circle;
    }

    public function setCircle(?string $circle): self
    {
        $this->circle = $circle;

        return $this;
    }

    public function getCircleType(): ?SaleMiaoCircleType
    {
        return $this->circleType;
    }

    public function setCircleType(?SaleMiaoCircleType $circleType): self
    {
        $this->circleType = $circleType;

        return $this;
    }

    /**
     * @return Collection|SaleMiaoProduct[]
     */
    public function getList(): Collection
    {
        return $this->list;
    }

    public function addList(SaleMiaoProduct $list): self
    {
        if (!$this->list->contains($list)) {
            $this->list[] = $list;
            $list->setMiao($this);
        }

        return $this;
    }

    public function removeList(SaleMiaoProduct $list): self
    {
        if ($this->list->contains($list)) {
            $this->list->removeElement($list);
            // set the owning side to null (unless already changed)
            if ($list->getMiao() === $this) {
                $list->setMiao(null);
            }
        }

        return $this;
    }
}
